//统一管理项目用户相关的接口

import request from "../../utils/request";
import type { loginForm ,loginResponseData,userResponseData,codeResponseData,baseResponseData,loginLogsResponseData} from "./type";
//统一管理接口
enum API{
    LOGIN_URL="/users/login",
    USERINFO_URL="/user/info",
    SEND_CODE_URL='/users/sendMsg',
    CHANGE_NAME_URL='users/change',
    LOGIN_LOGS_URL = '/logs/loginlogs',  // 获取登录日志接口路径
    
}

//暴露请求函数

//发送短信验证码接口
export const sendCodeAPI=(phone:string)=>request.post<any,codeResponseData>(API.SEND_CODE_URL,{phone})

//登录接口
export const loginAPI = (loginData: loginForm) => {
   
    return request.post<any, loginResponseData>(API.LOGIN_URL, loginData, {
        headers: {
            'Content-Type': 'application/json',
        }
    });
}



//获取用户信息接口方法
export const reqUserInfo=()=>request.get<any,userResponseData>(API.USERINFO_URL);

//修改用户名称接口方法
export const  reqChageUserName=(username:string)=>{
  //构建请求体
  const data={
    username
  }
    return request.put<any,baseResponseData>(API.CHANGE_NAME_URL,data)
};

// 获取登录日志接口方法
export const reqLoginLogs = (pageSize: number, pageNum: number) => {
    return request.get<any, loginLogsResponseData>(API.LOGIN_LOGS_URL, {
        params: {
            pageSize,
            pageNum
        }
    });
};
